<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Google地图</title>
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript" src="../internal.js"></script>
    <style type="text/css">
        *{color: #838383}
        body {
            font-size: 12px;
            width:540px;
            height: 350px;
            overflow: hidden;
            margin:0px;padding:0px;
        }
        .content{
            padding: 9px 0px 0px 15px;
            height:100%;
        }
        .content table{padding:0px;margin:0px;width: 100%}
        .content table tr{padding:0px;margin:0px; list-style: none;height: 30px; line-height: 30px;}
        #city,
        #address
        {height:21px;background: #FFF;border:1px solid #d7d7d7;padding: 0px; margin: 0px; line-height: 21px;}
        #city{width:90px}
        #address{width:220px}

         a.doSearch{display:block;text-align:center;line-height:24px; text-decoration: none;height:24px;width:95px;border: 0px;margin:0px;padding:0px;background:url(../../themes/default/images/icons-all.gif)  no-repeat;}
         a.doSearch:hover{background-position: 0 -30px;}
    </style>
</head>
<body>
<div class="content">
<table>
    <tr>
        <!--<td><label for="city">城市:</label></td>-->
        <!--<td><input id="city" type="text" value="北京市" /></td>-->
        <td><label for="address">地址:</label></td>
        <td><input id="address" type="text" value="北京市" /></td>
        <td><a href="javascript:doSearch()" class="doSearch">搜索</a></td>
    </tr>
</table>

<div id="container" style="width: 520px; height: 340px; border: 1px solid gray;"></div>
</div>
<script type="text/javascript">
    var map = new google.maps.Map(document.getElementById('container'), {
        zoom: 3,
        streetViewControl: false,
        scaleControl: true,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });
    var imgcss;
    var marker = new google.maps.Marker({
        map: map,
        draggable: true
    });
    function doSearch(){
        var address = document.getElementById('address').value;
        var geocoder = new google.maps.Geocoder();
        geocoder.geocode( { 'address': address}, function (results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                var bounds = results[0].geometry.viewport;
                map.fitBounds(bounds);
                marker.setPosition(results[0].geometry.location);
                marker.setTitle(address);
            } else alert('无法定位到该地址！');
        });
    }
    document.getElementById('address').onkeydown = function (evt){
        evt = evt || event;
        if (evt.keyCode == 13) {
            doSearch();
        }
    };
    dialog.onok = function (){
        var center = map.getCenter();
        var point = marker.getPosition();
        var url = "http://maps.google.com/maps/api/staticmap?center=" + center.lat() + ',' + center.lng() + "&zoom=" + map.zoom + "&size=520x340&maptype=" + map.getMapTypeId() + "&markers=" + point.lat() + ',' + point.lng() + "&sensor=false";
        editor.execCommand('inserthtml', '<img width="520" height="340" src="' + url + '"' + (imgcss ? ' style="' + imgcss + '"' :'') + '/>');
    };
    
    function getPars(str,par){
        var reg = new RegExp(par+"=((\\d+|[.,])*)","g");
        return reg.exec(str)[1];
    }
    var img = editor.selection.getRange().getClosedNode();
    if(img && img.src.indexOf("http://maps.google.com/maps/api/staticmap")!=-1){
        var url = img.getAttribute("src");
        var centers = getPars(url,"center").split(",");
        point = new google.maps.LatLng(Number(centers[0]),Number(centers[1]));
        map.setCenter(point);
        map.setZoom(Number(getPars(url,"zoom")));
        centers = getPars(url,"markers").split(",");
        marker.setPosition(new google.maps.LatLng(Number(centers[0]),Number(centers[1])));
        imgcss = img.style.cssText;
    }else{
        doSearch();
    }
</script>
</body>
</html>